/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.hiddendanger.mapper;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.koron.hiddendanger.bean.SafetyObservBean;
import com.koron.hiddendanger.domain.SafetyObserv;

public interface SafetyObservMapper {
	
	@Insert("insert into safety_observ(id,add_user,add_time,update_user,update_time,add_user_name,update_user_name,"
			+ "observer_code,observer_name,corp_code,dept_code,dept_name,grid_code,grid_name,grid_label,behavior_type_id,"
			+ "behavior_type_name,note,observ_date,observ_hours,safety_behavior,unsafe_behavior,safety_number,unsafe_number) values("
			+ "#{id},#{addUser},#{addTime},#{updateUser},#{updateTime},#{addUserName},#{updateUserName},"
			+ "#{observerCode},#{observerName},#{corpCode},#{deptCode},#{deptName},#{gridCode},#{gridName},#{gridLabel},#{behaviorTypeId},"
			+ "#{behaviorTypeName},#{note},#{observDate},#{observHours},#{safetyBehavior},#{unsafeBehavior},#{safetyNumber},#{unsafeNumber})")
	int insert(SafetyObserv bean);
	
	@Update("update safety_observ set update_user=#{updateUser},update_time=#{updateTime},update_user_name=#{updateUserName},"
			+ "dept_code=#{deptCode},dept_name=#{deptName},grid_code=#{gridCode},grid_name=#{gridName},grid_label=#{gridLabel},behavior_type_id=#{behaviorTypeId},"
			+ "behavior_type_name=#{behaviorTypeName},note=#{note},observ_date=#{observDate},observ_hours=#{observHours},"
			+ "safety_behavior=#{safetyBehavior},unsafe_behavior=#{unsafeBehavior},safety_number=#{safetyNumber},unsafe_number=#{unsafeNumber}"
			+ " where id=#{id}")
	int update(SafetyObserv bean);
	
	@Delete("delete from safety_observ where id=#{id}")
	int delete (@Param("id") String id);
	
	@Select("<script>"
			+ "select count(*) from safety_observ where 1=1"
			+ "<if test='observerCode!=null and !observerCode.isEmpty()'> and observer_code=#{observerCode} </if>"
			+ "<if test='observerName!=null'> and observer_name like CONCAT(CONCAT('%',#{observerName}),'%') </if>"
			+ "<if test='corpCode!=null and !corpCode.isEmpty()'> and corp_code=#{corpCode} </if>"
			+ "<if test='behaviorTypeId!=null and !behaviorTypeId.isEmpty()'> and behavior_type_id=#{behaviorTypeId} </if>"
			+ "<if test='gridCode!=null and !gridCode.isEmpty()'> and grid_code=#{gridCode} </if>"
			+ "<if test='deptCode!=null and !deptCode.isEmpty()'> and dept_code=#{deptCode} </if>"
			+ "<if test='biginDate!=null and !biginDate.isEmpty()'> and observ_date &gt;= #{biginDate} </if>"
			+ "<if test='endDate!=null and !endDate.isEmpty()'> and observ_date &lt;= #{endDate} </if>"
			+ "</script>")
	int count(@Param("observerCode") String observerCode,@Param("observerName") String observerName,
			@Param("corpCode") String corpCode,@Param("behaviorTypeId") String behaviorTypeId,
			@Param("gridCode") String gridCode,@Param("deptCode") String deptCode,@Param("biginDate") Date biginDate,@Param("endDate") Date endDate);

	@Select("<script>"
			+ "select * from safety_observ where 1=1"
			+ "<if test='observerCode!=null and !observerCode.isEmpty()'> and observer_code=#{observerCode} </if>"
			+ "<if test='observerName!=null'> and observer_name like CONCAT(CONCAT('%',#{observerName}),'%') </if>"
			+ "<if test='corpCode!=null and !corpCode.isEmpty()'> and corp_code=#{corpCode} </if>"
			+ "<if test='behaviorTypeId!=null and !behaviorTypeId.isEmpty()'> and behavior_type_id=#{behaviorTypeId} </if>"
			+ "<if test='gridCode!=null and !gridCode.isEmpty()'> and grid_code=#{gridCode} </if>"
			+ "<if test='deptCode!=null and !deptCode.isEmpty()'> and dept_code=#{deptCode} </if>"
			+ "<if test='biginDate!=null and !biginDate.isEmpty()'> and observ_date &gt;= #{biginDate} </if>"
			+ "<if test='endDate!=null and !endDate.isEmpty()'> and observ_date &lt;= #{endDate} </if>"
			+ "order by observ_date desc"
			+ "<if test='start!=null'> limit #{start},#{row}</if>"
			+ "</script>")
	List<SafetyObservBean> list(@Param("observerCode") String observerCode,@Param("observerName") String observerName,
			@Param("corpCode") String corpCode,@Param("behaviorTypeId") String behaviorTypeId,
			@Param("gridCode") String gridCode,@Param("deptCode") String deptCode,@Param("biginDate") Date biginDate,
			@Param("endDate") Date endDate,@Param("start") Integer start,@Param("row") Integer row);
	
	@Select("select * from safety_observ where id=#{id}")
	SafetyObservBean queryById(@Param("id") String id);
}
